package com.hspedu.seckill.utils;

import org.springframework.util.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author: xujiabing
 * @date: 2024-10-02 20:23
 * @description 校验工具类
 */
public class ValidatorUtil {
    //手机号校验
    private static final Pattern mobile_pattern = Pattern.compile("[1]([3-9])[0-9]{9}$");

    /**
     * 手机号合法性校验
     * @param mobile
     * @return
     */
    public static boolean isMobile(String mobile){
        if(!StringUtils.hasText(mobile)){
            return false;
        }
        Matcher matcher = mobile_pattern.matcher(mobile);
        return matcher.matches();//返回校验结果true 为正确
    }

    public static void main(String[] args) {
        boolean mobile = ValidatorUtil.isMobile("13380808081");
        System.out.println(mobile);
    }
}
